<?php
namespace app\api\controller;
use app\common\controller\CommonController;
use app\api\model\TaskModel;
use app\common\errcode\ApiErrCode;
use app\common\errcode\ApiErrMsg;
use think\Db;

class MessageController extends CommonController
{
    public function send()
    {
        $data = $this->request->post();
        if (empty($data['tid'])) {
            return $this->jsonJump(ApiErrCode::PARAM_ERROR,ApiErrMsg::PARAM_ERROR);
        }
        $tid = $data['tid'];
        $taskModel = new TaskModel();
        $taskinfo = $taskModel->get_task_info_by_tid($tid);
        if (empty($taskinfo)) {
            return $this->jsonJump(ApiErrCode::TASK_NOT_EXIST,ApiErrMsg::TASK_NOT_EXIST);
        }
        $info = [
            'to_email'          => $taskinfo['charge_email'],
            'to_username'       => $taskinfo['charge_username'],
            'task_name'         => $taskinfo['name'],
            'finish_date'       => $taskinfo['finish_date'],
        ];
        $emailObj = new \app\common\tool\Email;
        $result = $emailObj->handle_send('TASK_HAS_EXPIRED', $info);
        if($result){
            return $this->jsonJump(ApiErrCode::SUCCESS,ApiErrMsg::SUCCESS);
        }else {
            return $this->jsonJump(ApiErrCode::SEND_FAIL,ApiErrMsg::SEND_FAIL);    
        }        
    }    
}